###
#
#      ScriptJobs.ps1
#
# Takes the parameter sqlserver and scripts the SQL Server Agent jobs to files
# ending .Job.sql
#
# v1 - Created 20100915 15:00 by Darren Comeau - Initial version scripts the jobs
#      within the instance to files in the working directory with no error handling.
#
###


param($sqlserver)

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Smo') | Out-Null

$srv = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlserver

$jobs = $srv.JobServer.Jobs


ForEach ( $job in $jobs )
	{
		$jobname = $job.Name + ".Job.sql"
		$job.Script() | Out-File $jobname
	}